#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;

long long arr[1010][1010];
int main()
{
    int n, m, q; cin >> n >> m >> q;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            int x; cin >> x;
            arr[i][j] = arr[i - 1][j] + arr[i][j - 1] - arr[i - 1][j - 1] + x;
        }
    while (q--)
    {
        int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2;
        cout << arr[x2][y2] - arr[x1 - 1][y2] - arr[x2][y1 - 1] + arr[x1 - 1][y1 - 1] << endl;
    }
    return 0;
}

#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int arr[N];
long long sum[N];
int main()
{
    int n, q; cin >> n >> q;
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
        if (1 == i) sum[i] = arr[i];
        else sum[i] = sum[i - 1] + arr[i];
    }
    while (q--)
    {
        int l, r; cin >> l >> r;
        cout << sum[r] - sum[l - 1] << endl;
    }

    return 0;
}

#include<iostream>
using namespace std;
const int N = 1e6 + 10;
int arr[N];
int sum[N];
int main()
{
    int n; cin >> n;
    int max_sum = -99999999;
    int min_sum = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
        sum[i] = sum[i - 1] + arr[i];
        max_sum = max(max_sum, sum[i] - min_sum);
        min_sum = min(sum[i], min_sum);
    }
    cout << max_sum << endl;
    return 0;
}